<template>
  <div className="fixed-table">
    <basic-container>
         <el-table
          :data="tableData"
          
          style="width: 100%">
          <el-table-column
          fixed
          prop="company"
          label="公司名称"
          align="center"
          header-align="center">
           <template slot-scope="scope">
            <span v-if="scope.row.company">{{scope.row.company}}</span>
            <span v-else style="color:#999">未知公司</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="pname"
          label="职位名称"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="pubtime"
          label="发布时间"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="city"
          label="城市"
          align="center"
          header-align="center"
          >
          <template slot-scope="scope">
            <span v-if="City.city_list[scope.row.city]===undefined" style="color:#999">未知城市</span>
            <span v-else>{{City.city_list[scope.row.city]}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="salaryMin"
          label="最低工资(万)"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="salaryMax"
          label="最高工资(万)"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="payment"
          label="伯乐奖金(元)"
          align="center"
          header-align="center">
        </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            header-align="center">
            <template slot-scope="scope">
              <el-button @click="handlePas(scope.row,scope.$index)" type="text" size="small">允许发布</el-button>
              <el-button type="text" size="small" @click="handleNeg(scope.row,scope.$index)">拒绝发布</el-button>
            </template>
          </el-table-column>
        </el-table>
        <br/>
      <el-row type="flex" justify="center">
        
          <el-pagination
            style="align-self:center"
            background
            layout="prev, pager, next"
            :current-page="currentPage"
            :page-count="totalPage"
            @current-change="changePage">
          </el-pagination>
        
      </el-row>
    </basic-container>
  </div>
</template>

<script>
import BasicContainer from '@vue-materials/basic-container'
import Config from '@myconfig/config.min.js'
import City from '@myconfig/city.min.js'

  export default {
  components: { BasicContainer },
  name: 'FixedTable',

  data() {
    return {
      City: City,
      currentPage:1,
      totalPage: 10,
      tableData: []
    }
  },
  methods: {
    handlePas(row,index){
      this.$http.post(Config.baseUrl + '/api/position/verify/' + row.id + '/pass').then(
        function(rsp){
          if(rsp.data.code == 1 ){
            this.$message({
              message: '通过职位审核成功',
              type: 'success'
            });
            this.tableData.splice(index,1)
          }else{
            this.$message({
              message: '通过职位审核失败',
              type: 'error'
            });
          }
        },function(error){
            this.$message({
              message: '通过职位审核失败',
              type: 'error'
            });
        }
      )
    },
    handleNeg(row) {
      this.$http.post(Config.baseUrl + '/api/position/verify/' + row.id + '/reject').then(
        function(rsp){
          if(rsp.data.code == 1 ){
            this.$message({
              message: '拒绝职位审核成功',
              type: 'warning'
            });
            this.tableData.splice(index,1)
          }else{
            this.$message({
              message: '拒绝职位审核失败',
              type: 'error'
            });
          }
        },function(error){
            this.$message({
              message: '拒绝职位审核失败',
              type: 'error'
            });
        }
      )
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    getData(currentPage){
      this.$http.get(Config.baseUrl+'/api/positions/noverify/'+currentPage).then(function(rsp){
      console.log('====================================');
      console.log(rsp);
      this.tableData = rsp.data.list
      this.totalPage = rsp.data.pages
      console.log('====================================');
      // this.totalPage = rsp.data.pages
      
      },function(error){
        console.log('====================================');
        console.log(error);
        console.log('====================================');
      })
    },
    changePage:function(currentPage){
      console.log('====================================');
      console.log('pageÇhange new Page' + currentPage);
      console.log('====================================');
      this.getData(currentPage)
    }
  },
  created(){
    console.log('====================================');
    console.log('created');
    console.log('====================================');
    this.getData(1)
  },
  mounted(){
    console.log('====================================');
    console.log('mounted');
    console.log('====================================');
  }
}
</script>

<style>
  .fixed-table {

  }
</style>
